package Screens;

import Controllers.HdChamadosJpaController;
import Controllers.HdEquipamentoJpaController;
import Controllers.HdSetoresJpaController;
import Controllers.HdTipoEquipamentoJpaController;
import Controllers.HdTipoProblemaJpaController;
import Controllers.HdTipoUserJpaController;
import Controllers.HdUsersJpaController;
import Entities.HdChamados;
import Entities.HdEquipamento;
import Entities.HdSetores;
import Entities.HdTipoEquipamento;
import Entities.HdTipoProblema;
import Entities.HdTipoUser;
import Entities.HdUsers;
import TableModels.ChamadosUsersTableModel;
import TableModels.EquipamentoRelatorioTableModel;
import TableModels.SetoresRelatorioTableModel;
import TableModels.TipoEquipamentoRelatorioTableModel;
import TableModels.TipoProblemaRelatorioTableModel;
import TableModels.TipoUserRelatorioTableModel;
import TableModels.UsersRelatorioTableModel;
import Util.EMFConection;
import java.util.List;

/**
 *
 * @author Douglas
 */
public class TelaPrincipalSuporte extends javax.swing.JFrame {

    /**
     * Creates new form TelaPrincipal
     */
    public TelaPrincipalSuporte() {
        initComponents();
        btRefreshActionPerformed(null);
        tbChamados.getTableHeader().setReorderingAllowed(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbChamados = new javax.swing.JTable();
        btRefresh = new javax.swing.JButton();
        btSair = new javax.swing.JButton();
        btEditarUsuario = new javax.swing.JButton();
        btEditarChamado = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btAbrirChamado = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnCadastro = new javax.swing.JMenu();
        mnCadastroUsuario = new javax.swing.JMenuItem();
        mnCadastroTipoUsuario = new javax.swing.JMenuItem();
        mnCadastroEquipamento = new javax.swing.JMenuItem();
        mnCadastroTipoEquipamento = new javax.swing.JMenuItem();
        mnCadastroSetores = new javax.swing.JMenuItem();
        mnCadastroTipoProblema = new javax.swing.JMenuItem();
        mnRelatorio = new javax.swing.JMenu();
        mnUsuarios = new javax.swing.JMenuItem();
        mnEquipamentos = new javax.swing.JMenuItem();
        mnSetores = new javax.swing.JMenuItem();
        mnTpEquipamento = new javax.swing.JMenuItem();
        mnTpProblema = new javax.swing.JMenuItem();
        mnTpUser = new javax.swing.JMenuItem();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Help Desk");
        setResizable(false);

        tbChamados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tbChamados);

        btRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Refresh.png"))); // NOI18N
        btRefresh.setText("Atualizar Chamados");
        btRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRefreshActionPerformed(evt);
            }
        });

        btSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/exit.png"))); // NOI18N
        btSair.setText("Sair");
        btSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairActionPerformed(evt);
            }
        });

        btEditarUsuario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Cadastro.png"))); // NOI18N
        btEditarUsuario.setText("Editar Usuario");
        btEditarUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarUsuarioActionPerformed(evt);
            }
        });

        btEditarChamado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Editar.png"))); // NOI18N
        btEditarChamado.setText("EditarChamado");
        btEditarChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarChamadoActionPerformed(evt);
            }
        });

        jLabel1.setText("Chamados: ");

        btAbrirChamado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/new.png"))); // NOI18N
        btAbrirChamado.setText("Abrir Chamados");
        btAbrirChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAbrirChamadoActionPerformed(evt);
            }
        });

        mnCadastro.setText("Cadastro");

        mnCadastroUsuario.setText("Usuário");
        mnCadastroUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroUsuarioActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroUsuario);

        mnCadastroTipoUsuario.setText("Tipo de Usuário");
        mnCadastroTipoUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroTipoUsuarioActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroTipoUsuario);

        mnCadastroEquipamento.setText("Equipamento");
        mnCadastroEquipamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroEquipamentoActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroEquipamento);

        mnCadastroTipoEquipamento.setText("Tipo de Equipamento");
        mnCadastroTipoEquipamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroTipoEquipamentoActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroTipoEquipamento);

        mnCadastroSetores.setText("Setores");
        mnCadastroSetores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroSetoresActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroSetores);

        mnCadastroTipoProblema.setText("Tipo de Problema");
        mnCadastroTipoProblema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnCadastroTipoProblemaActionPerformed(evt);
            }
        });
        mnCadastro.add(mnCadastroTipoProblema);

        jMenuBar1.add(mnCadastro);

        mnRelatorio.setText("Relatório");

        mnUsuarios.setText("Usuários");
        mnUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnUsuariosActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnUsuarios);

        mnEquipamentos.setText("Equipamentos");
        mnEquipamentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnEquipamentosActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnEquipamentos);

        mnSetores.setText("Setores");
        mnSetores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnSetoresActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnSetores);

        mnTpEquipamento.setText("Tipo de Equipamentos");
        mnTpEquipamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnTpEquipamentoActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnTpEquipamento);

        mnTpProblema.setText("Tipo de Problema");
        mnTpProblema.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnTpProblemaActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnTpProblema);

        mnTpUser.setText("Tipo de Usuario");
        mnTpUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnTpUserActionPerformed(evt);
            }
        });
        mnRelatorio.add(mnTpUser);

        jMenuBar1.add(mnRelatorio);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 710, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(btAbrirChamado, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btEditarUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btEditarChamado, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btSair, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(btAbrirChamado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btEditarUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btEditarChamado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btSair, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-746)/2, (screenSize.height-480)/2, 746, 480);
    }// </editor-fold>//GEN-END:initComponents

    private void mnCadastroUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroUsuarioActionPerformed
        new CadastroUsers().setVisible(true);
    }//GEN-LAST:event_mnCadastroUsuarioActionPerformed

    private void mnCadastroTipoUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroTipoUsuarioActionPerformed
        new CadastroTipoUsers().setVisible(true);
    }//GEN-LAST:event_mnCadastroTipoUsuarioActionPerformed

    private void mnCadastroEquipamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroEquipamentoActionPerformed
        new CadastroEquipamento().setVisible(true);
    }//GEN-LAST:event_mnCadastroEquipamentoActionPerformed

    private void mnCadastroTipoEquipamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroTipoEquipamentoActionPerformed
        new CadastroTipoEquipamento().setVisible(true);
    }//GEN-LAST:event_mnCadastroTipoEquipamentoActionPerformed

    private void mnCadastroSetoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroSetoresActionPerformed
        new CadastroSetores().setVisible(true);
    }//GEN-LAST:event_mnCadastroSetoresActionPerformed

    private void mnCadastroTipoProblemaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnCadastroTipoProblemaActionPerformed
        new CadastroTipoProblema().setVisible(true);
    }//GEN-LAST:event_mnCadastroTipoProblemaActionPerformed

    private void btRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRefreshActionPerformed
        HdChamadosJpaController chamadosJpaController = new HdChamadosJpaController(EMFConection.getInstance());
        
        List<HdChamados> list = chamadosJpaController.findHdChamadosEntities();
        
        tbChamados.setModel(ChamadosUsersTableModel.addAllChamados(list));
    }//GEN-LAST:event_btRefreshActionPerformed

    private void btEditarUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarUsuarioActionPerformed
        new EscolherUserEditar().setVisible(true);
    }//GEN-LAST:event_btEditarUsuarioActionPerformed

    private void btEditarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarChamadoActionPerformed
        HdChamadosJpaController chamadosJpaController = new HdChamadosJpaController(EMFConection.getInstance());
        HdChamados chamado = chamadosJpaController.findHdChamados(tbChamados.getSelectedRow()+1);
        
        if (chamado != null){
            new EditarChamados(chamado).setVisible(true);
        }
    }//GEN-LAST:event_btEditarChamadoActionPerformed

    private void btSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btSairActionPerformed

    private void mnUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnUsuariosActionPerformed
        HdUsersJpaController usersJpaController = new HdUsersJpaController(EMFConection.getInstance());
        List<HdUsers> listUsers = usersJpaController.findHdUsersEntities();
        new Relatorios(UsersRelatorioTableModel.addAllUsers(listUsers)).setVisible(true);
    }//GEN-LAST:event_mnUsuariosActionPerformed

    private void btAbrirChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAbrirChamadoActionPerformed
        new CadastroChamado().setVisible(true);
    }//GEN-LAST:event_btAbrirChamadoActionPerformed

    private void mnEquipamentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnEquipamentosActionPerformed
        HdEquipamentoJpaController equipamentoJpaController = new HdEquipamentoJpaController(EMFConection.getInstance());
        List<HdEquipamento> listEquipamento = equipamentoJpaController.findHdEquipamentoEntities();
        new Relatorios(EquipamentoRelatorioTableModel.addAllEquipamento(listEquipamento)).setVisible(true);
    }//GEN-LAST:event_mnEquipamentosActionPerformed

    private void mnTpEquipamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnTpEquipamentoActionPerformed
        HdTipoEquipamentoJpaController tipoEquipamentoJpaController = new HdTipoEquipamentoJpaController(EMFConection.getInstance());
        List<HdTipoEquipamento> listTipoEquipamento = tipoEquipamentoJpaController.findHdTipoEquipamentoEntities();
        new Relatorios(TipoEquipamentoRelatorioTableModel.addAllTipoEquipamento(listTipoEquipamento)).setVisible(true);
    }//GEN-LAST:event_mnTpEquipamentoActionPerformed

    private void mnTpProblemaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnTpProblemaActionPerformed
        HdTipoProblemaJpaController tipoProblemaJpaController = new HdTipoProblemaJpaController(EMFConection.getInstance());
        List<HdTipoProblema> listTipoProblema = tipoProblemaJpaController.findHdTipoProblemaEntities();
        new Relatorios(TipoProblemaRelatorioTableModel.addAllTipoProblema(listTipoProblema)).setVisible(true);        
    }//GEN-LAST:event_mnTpProblemaActionPerformed

    private void mnTpUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnTpUserActionPerformed
        HdTipoUserJpaController tipoUserJpaController = new HdTipoUserJpaController(EMFConection.getInstance());
        List<HdTipoUser> listTipoUser = tipoUserJpaController.findHdTipoUserEntities();
        new Relatorios(TipoUserRelatorioTableModel.addAllTipoUsers(listTipoUser)).setVisible(true);
    }//GEN-LAST:event_mnTpUserActionPerformed

    private void mnSetoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnSetoresActionPerformed
        HdSetoresJpaController setoresJpaController = new HdSetoresJpaController(EMFConection.getInstance());
        List<HdSetores> listSetores = setoresJpaController.findHdSetoresEntities();
        new Relatorios(SetoresRelatorioTableModel.addAllSetores(listSetores)).setVisible(true);
    }//GEN-LAST:event_mnSetoresActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAbrirChamado;
    private javax.swing.JButton btEditarChamado;
    private javax.swing.JButton btEditarUsuario;
    private javax.swing.JButton btRefresh;
    private javax.swing.JButton btSair;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu mnCadastro;
    private javax.swing.JMenuItem mnCadastroEquipamento;
    private javax.swing.JMenuItem mnCadastroSetores;
    private javax.swing.JMenuItem mnCadastroTipoEquipamento;
    private javax.swing.JMenuItem mnCadastroTipoProblema;
    private javax.swing.JMenuItem mnCadastroTipoUsuario;
    private javax.swing.JMenuItem mnCadastroUsuario;
    private javax.swing.JMenuItem mnEquipamentos;
    private javax.swing.JMenu mnRelatorio;
    private javax.swing.JMenuItem mnSetores;
    private javax.swing.JMenuItem mnTpEquipamento;
    private javax.swing.JMenuItem mnTpProblema;
    private javax.swing.JMenuItem mnTpUser;
    private javax.swing.JMenuItem mnUsuarios;
    private javax.swing.JTable tbChamados;
    // End of variables declaration//GEN-END:variables
}
